package com.csdj.wenjun.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class QQyouxiang {
    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String sender;


    @Async
    public boolean sendMail(String to, String subject, String content) {

        System.out.println(sender);
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setFrom(sender);
        mailMessage.setTo(to);
        mailMessage.setSubject(subject);
        mailMessage.setText(content);
        try {
             javaMailSender.send(mailMessage);
             return true;
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("发送简单邮件失败");
        }
        return false;
    }
}